<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: HUI
  Date: 2020/12/14
  Time: 14:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>图书管理</title>
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

    <div class="container">
        <div class="row">
            <div class="col-md-4" >
                <form method="post" action="/searchBook">
                    <label for="bookName" >名称</label>
                    <input type="text" name="bookName" id="bookName">
                    <input type="submit" value="搜索" class="btn btn-info btn-sm" >
                    <a href="/addBook" class="btn btn-info btn-sm">添加</a>
                </form>

            </div>
            <div class="col-md-8">
            </div>

        </div>

        <div class="row">

            <table class="table">
                <thead>
                    <th>书籍编号</th>
                    <th>书籍名称</th>
                    <th>书籍数量</th>
                    <th>书籍详情</th>
                    <th>分类</th>
                    <th>书籍编辑</th>
                </thead>
                <tbody>
                <c:forEach var="book" items="${bookList}">
                    <tr>
                        <td>${book.bookID}</td>
                        <td>${book.bookName}</td>
                        <td>${book.bookCounts}</td>
                        <td>${book.detail}</td>
                        <td>${book.className}</td>
                        <td>
<%--                            <button type="button" id="editBook" onclick="" class="btn btn-info btn-sm">修改</button>--%>
                            <a href="/editBook/${book.bookID}" class="btn btn-info btn-sm">修改</a>
                            <button type="button" onclick="delBook(this)" class="btn btn-danger btn-sm">删除</button>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>

            </table>
        </div>

    </div>

<script type="text/javascript">
    //删除图书
    function delBook(obj){
        const id = $(obj).parent().parent().children('td').eq(0).text();
        if(confirm("确定是否删除？")){
            $.get("/delBook/"+id,function(data,status){
                console.log(status)
            });
            $(obj).parent().parent().remove();
        }
    }
</script>

</body>
</html>
